package com.ad.pet.app.splash;

import android.app.Activity;

import com.ad.pet.api.ApiService;
import com.ad.pet.app.RxDisposable;
import com.ad.pet.common.data.http.AppSubscriber;
import com.ad.pet.common.data.injector.PerActivity;
import com.ad.pet.common.structure.mvp.AbsBasePresenter;
import com.ad.pet.models.remote.home.BigAdver;

import javax.inject.Inject;

/**
 * Created by SEELE on 2019/3/21.
 */
@PerActivity
public class WelcomePresenter extends AbsBasePresenter implements WelcomeContract.Presenter{
    private ApiService mApiService;
    private WelcomeContract.View mView;

    private Activity mActivity;

    private RxDisposable mRxDisposable;
    @Inject
    public WelcomePresenter(ApiService apiService,
                              Activity activity, RxDisposable rxDisposable) {
        mApiService = apiService;
        mActivity = activity;
        mRxDisposable = rxDisposable;
    }
    @Override
    public void onCreate(WelcomeContract.View view) {
        this.mView = view;
    }

    @Override
    public void onDestroy() {
        if (mRxDisposable != null)
            mRxDisposable.clear();
        if (mActivity != null) mActivity = null;
        mView = null;
    }


    @Override
    public void getBootAdver(String width, String height) {
        mRxDisposable.add(mApiService.getBootAdver(width,height)
                .subscribe(new AppSubscriber<BigAdver>(mView) {
                    @Override
                    public void next(BigAdver list) {
                        mView.getBootAdverSuccess(list);
                    }
                }));
    }
}
